<script setup lang="ts">
import { useRoute } from "vue-router";
import { onMounted, ref } from "@vue/runtime-core"
import axios from "axios";
import { debounce } from 'lodash-es'



interface ActorInfoType {
    avatar: string
    name: string
    height: number
    weight: number
    fansCount: string
}

interface Comments {
    comments: number
}

interface ItemExplainList {
    cover: string
    title: string
    discountPrice: string
}

interface CommentsArr {
    avatar: string
    userName: string
    time: string
    content: string
}

const route = useRoute();
const itemIdUrl = route.query.actorIdUrl
const actorIdUrl = route.query.actorIdUrl
const urlVideo = ref<string>()
const actorInfo = ref<ActorInfoType>()
const comments = ref<Comments>()
const itemInfo = ref<ItemExplainList>()
const avatars = ref<[]>()
const loading = ref(true)
const commentsArr = ref<CommentsArr[]>([])
const show = ref(false);

const showPopup = () => {
    show.value = true;
};

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const _debounce = debounce(showPopup)

const getDetail = () => {
    axios
        .get(`https://apis.netstart.cn/mogujie/video/detail?itemId=${itemIdUrl}&actorId=${actorIdUrl}`)
        .then((({ data }) => {
            // console.log(itemExplainList.value = data.data.itemExplainList[0]);
            // itemExplainList.value = data.data.itemExplainList[0]
            urlVideo.value = data.data.itemExplainList[0].videoInfo.url
            actorInfo.value = data.data.itemExplainList[0].actorInfo
            comments.value = data.data.itemExplainList[0].comments?.length
            itemInfo.value = data.data.itemExplainList[0].itemInfo
            avatars.value = data.data.hotLink.avatars
            commentsArr.value = data.data.itemExplainList[0].comments.map((i: CommentsArr) => {
                return {
                    avatar: i.avatar,
                    userName: i.userName,
                    time: i.time,
                    content: i.content
                }
            })
            console.log(data.dataitemExplainList[0].comments);
            loading.value = false
        }))
}

onMounted(() => {
    getDetail()
    console.log(itemIdUrl, '///', actorIdUrl);

})
</script>

<template>
    <div class="video-box">
        <!-- {{ item }}//{{ actor }} -->
        <div class="playback">
            <video :src="urlVideo" style="width: 100%;height: 100%;object-fit: fill" controls></video>
            <div class="hot">
                <div class="hot-img" v-for="(h, i) in avatars" :key="i">
                    <img :src="h">
                </div>
                <div class="hot-item">热门直播 ></div>
            </div>
            <div class="right-bar">
                <div class="bar-img">
                    <img :src="actorInfo?.avatar">
                </div>
                <div class="shoucang">
                    <img src="@/assets/img/shoucang.png">
                    <div class="r-it">收藏</div>
                </div>
                <div class="pinlun" type="primary" @click="showPopup()">
                    <img src="@/assets/img/pinlun.png">
                    <div class="r-it">{{ comments ? comments : '评价' }}</div>
                </div>

                <div class="gouwuche">
                    <img src="@/assets/img/gouwuche.png">
                    <div class="r-it">购物车</div>
                </div>
            </div>
            <div class="avatar">
                <div class="avatar-name">{{ actorInfo?.name }}</div>
                <div class="avatar-num">
                    {{ actorInfo?.height }}cm {{ actorInfo?.weight
                    }}kg ||
                    {{ actorInfo?.fansCount }}
                </div>
            </div>
            <div class="goods">
                <div class="goode-img">
                    <img :src="itemInfo?.cover">
                </div>
                <div class="goods-item">
                    <div class="item">{{ itemInfo?.title }}</div>
                    <div class="price"><span class="one">待秒杀</span> <span class="two">¥{{
                            itemInfo?.discountPrice
                    }}</span>¥</div>
                </div>
                <div class="btn-r">立即购买</div>
            </div>
            <van-popup v-model:show="show" position="bottom" :close-on-click-overlay="true" round closeable
                close-icon-position="top-right" close-icon="closs" overlay :style="{ height: '60%' }">
                <div class="appraise" v-for="(c, i) in commentsArr" :key="i">
                    <div class="appraise-top">
                        <div class="user-img">
                            <van-image lazy-load :src="c.avatar" />
                        </div>
                        <div class="user">
                            <div class="user-name">{{ c.userName }}</div>
                            <div class="time">{{ c.time }}</div>
                        </div>
                    </div>
                    <div class="appraise-title">{{ c.content }}</div>
                    <div class="bor-bottom"></div>
                </div>
            </van-popup>
        </div>

        <van-loading size="24px" vertical v-if="loading">加载中...</van-loading>
    </div>
</template>

<style lang="scss" scoped>
.playback {
    position: relative;
    width: 100vw;
    height: 100vh;

    .hot {
        display: flex;
        width: 130px;
        align-items: center;
        position: absolute;
        top: 5px;
        left: 5px;
        padding: 3px 6px;
        border-radius: 20px;
        background-color: rgba(0, 0, 0, 0.5);
        justify-content: space-between;

        .hot-img {
            width: 30px;
            height: 30px;
            border-radius: 999px;
            overflow: hidden;
            border: 1px solid #fff;

            img {
                width: 100%;
                height: 100%;
            }

            &:nth-child(2) {
                position: absolute;
                left: 22px;
                border: 1px solid #fff;
            }

            &:nth-child(3) {
                position: absolute;
                left: 40px;
                border: 1px solid #fff;
            }
        }

        .hot-item {
            margin-left: 3px;
            color: #fff;
            font-size: 12px;
        }
    }

    .right-bar {
        position: absolute;
        display: flex;
        right: 5px;
        top: 27%;
        flex-direction: column;
        justify-content: space-around;
        align-items: center;
        height: 220px;

        .bar-img {
            width: 35px;
            height: 35px;
            border-radius: 999px;
            overflow: hidden;

            img {
                width: 100%;
                height: 100%;
            }
        }

        .shoucang,
        .pinlun,
        .gouwuche {
            display: flex;
            flex-direction: column;
            align-items: center;
            width: 35px;
            height: 35px;

            img {
                width: 100%;
                height: 100%;
            }

            .r-it {
                color: #fff;
                font-size: 12px;

                &:last-child {
                    white-space: nowrap;
                }
            }
        }
    }

    .avatar {
        position: absolute;
        bottom: 148px;
        left: 6px;

        .avatar-name {
            color: #fff;
        }

        .avatar-num {
            font-size: 12px;
            color: hsla(0, 0%, 100%, .6);
        }

    }

    .goods {
        position: absolute;
        display: flex;
        justify-content: space-around;
        align-items: center;
        width: 94vw;
        background-color: rgba(0, 0, 0, 0.2);
        border-radius: 4px;
        margin-left: 7px;
        bottom: 80px;

        .goode-img {
            width: 50px;
            height: 50px;

            img {
                width: 100%;
                height: 100%;
            }
        }

        .goods-item {
            display: flex;
            flex-direction: column;
            justify-content: space-around;

            width: 200px;

            .item {
                margin-bottom: 5px;
                overflow: hidden;
                color: #fff;
                font-size: 12px;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
        }

        .price {
            font-size: 12px;

            .one {
                background: linear-gradient(150deg, #fb872c, #fc4441);
                color: #fff;
                font-size: 12px;
            }

            .two {
                margin-right: 3px;
                font-size: 14px;
                font-weight: 600;
                color: #fa4e82;
            }
        }

        .btn-r {
            width: 70px;
            height: 25px;
            line-height: 25px;
            color: #fff;
            font-size: 12px;
            text-align: center;
            border-radius: 999px;
            background-color: #f46;
        }
    }


}

:deep(.el-drawer) {
    height: 50%;
}

:deep(.el-drawer.btt) {
    width: 100%;

    background-image: url(@/assets/img/pinlun-bg.png);
}

:deep(.el-drawer__header) {
    align-items: center;
    color: #72767b;
    display: flex;
    margin-bottom: 32px;
    padding: 5px 0 0 5px;
}

:deep(.van-popup) {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100vw;
    background-color: #fff;
}

:deep(.van-badge__wrapper.van-icon.van-icon-close.van-popup__close-icon.van-popup__close-icon--top-right.van-haptics-feedback) {
    display: inline-block;
    height: 20px;
    width: 20px;
    background-color: #fc4441;
}

.appraise {
    color: #fff;

    .appraise-top {
        display: flex;
        flex-direction: row;
        align-items: center;
        margin-top: 15px;

        .user-img {
            width: 30px;
            height: 30px;
            margin-left: 7px;
            border-radius: 999px;
            overflow: hidden;

            img {
                width: 100%;
                height: 100%;
            }
        }

        .user {
            margin-left: 7px;

            .user-name {
                color: #999;
                font-size: 12px;
            }

            .time {
                margin-top: 3px;
                color: #999;
                font-size: 12px;
            }


        }
    }

    .appraise-title {
        margin: 5px 45px 25px;
        font-size: 12px;
        color: #000;
    }

    .bor-bottom {
        margin-left: 45px;
        height: 1px;
        background-color: #72767b;
    }
}
</style>